<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Promise.allSettled</title>
</head>

<body>

  <script>
    // 声明一个Promise对象
    const p1 = new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve("商品数据-1")
      }, 1000)
    })

    const p2 = new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve("商品数据-2")
      }, 1000)
    })

    const p3 = new Promise((resolve, reject) => {
      setTimeout(() => {
        reject("失败了")
      }, 1000)
    })

    /*     // Promise.allSettled() 返回的状态总是成功的，返回值为传入 Promise 对象的结果
        const result = Promise.allSettled([p1, p2])
        console.log(result); // Promise {<fulfilled>: [ {status: 'fulfilled', value: '商品数据-1'}, {status: 'fulfilled', value: '商品数据-2'} ]}
    
        const result2 = Promise.allSettled([p1, p3])
        console.log(result2); // Promise {<fulfilled>: [ {status: 'fulfilled', value: '商品数据-1'}, {status: 'rejected', reason: '失败了'} ]}
     */
    // Promise.all() 返回值 一假便假 值为失败Promise对象的值
    const result = Promise.all([p1, p3])
    console.log(result); // {<rejected>: 失败了}

  </script>
</body>

</html>